package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RegDemo {
    public static void main(String[] args) {
        try {
            UerInfo uerInfo = InputUtil.getInputObject(new UerInfo(), "欢迎注册");//方法名 getInputObject 暗示它的作用是从用户输入中获取数据，并将其封装到一个对象new UserInfo()中，title是控制台提示语
            Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement();
            String sql = "INSERT INTO userinfo(username,password,nickname,age) VALUES ('"+uerInfo.getUsername()+"','"+uerInfo.getPassword()+"','"+uerInfo.getNickname()+"','"+uerInfo.getAge()+"')";
            int number = statement.executeUpdate(sql);
            System.out.println(number>0?"注册成功":"注册失败");
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
